home *** CD-ROM | disk | FTP | other *** search
- /////////////////
- //tut_lib.bhs
- //Joshua Mitnick
- //July 11, 2002
- /////////////////
-
- /**********************************************************************/
- /*Use these descriptions as a template for your own specific scenarios*/
- /**********************************************************************/
-
- //civil_war_by_percent (1, 2, 50);
- //50% of Player 1's military units will switch over to Player 2's team.
-
- //civil_war_by_number (1, 2, 4);
- //4 of Player 1's military units will switch over to Player 2's team.
-
- //city_rebellio (2, "Orleans", 10);
- //The city of Orleans and all units and buildings within a 10 tile radius
- //will switch to Player 2's team.
-
- //all_object_type_selected (Player, "Light Camel");
- //Player has selected all of the Light Camels
-
- /*****************************************************************/
-
- //============================================================
- scenario civil_war_by_percent (Empire, Rebels, percent) {
- total_military = num_military_units (Empire);
- amount_of_rebels = (real)total_military * ((real) percent/100.0);
- for (i = 0; i < amount_of_rebels; i ++) {
- Unit_ID = find_military (Empire);
- new_id = switch_teams (Rebels, Empire, Unit_ID);
- }
- return amount_of_rebels;
- }
- //============================================================
-
-
- //============================================================
- scenario all_gen_entrench (Player) {
- num_of_generals = num_type (Player, "General");
- for (i = 0; i < num_of_generals; i ++) {
- general_entrench (Player, find_unit (Player, "General"));
- }
- return num_of_generals;
- }
- //============================================================
-
-
- //============================================================
- scenario civil_war_by_number (Empire, Rebels, amount_of_rebels) {
- for(i = 0; i < amount_of_rebels; i ++) {
- Unit_ID = find_military (Empire);
- new_id = switch_teams (Rebels, Empire, Unit_ID);
- }
- }
- //============================================================
-
-
- //============================================================
- scenario city_rebellion (Rebels, City_Name, Radius) {
- City_ID = find_city_id (City_Name);
- City_Owner = find_city_owner (City_Name);
- City_ID = switch_teams (Rebels, City_Owner, City_ID);
- Counter = 0;
- while (any_object_near_build (City_Owner, 1, Rebels, City_ID, Radius)) {
- if (object_near_build (City_Owner, Counter, Rebels, City_ID, Radius)) {
- new_id = switch_teams (Rebels, City_Owner, Counter);
- }
- Counter ++;
- }
- }
- //============================================================
-
-
- scenario all_object_type_selected (Player, Unit) {
- all_selected = true;
- Repeat_ID = find_unit (Player, Unit);
- Count = 1;
- if (Repeat_ID == -1){
- all_selected = false;
- }
- else{
- while (Repeat_ID != find_unit (Player, Unit)){
- ++ Count;
- }
- if (!object_selected (Player, Repeat_ID)){
- all_selected = false;
- }
- for (UnitCount = 0; UnitCount < Count; ++ UnitCount){
- UnitID = find_unit (Player, Unit);
- if (!object_selected (Player, UnitID)){
- all_selected = false;
- }
- }
- }
- return all_selected;
- }
-
- //============================================================
- scenario all_object_type_onscreen_selected (Player, Unit) {
-
- for( i = 0; i < num_type( Player, Unit); i++ ) {
- unit_id = find_unit( Player, Unit );
- unit_x = object_position_x( Player, unit_id );
- unit_y = object_position_y( Player, unit_id );
- if( !object_selected( Player, unit_id ) && is_on_screen( unit_x, unit_y) ) {
- return false;
- }
- }
-
- return true;
-
- /*
- all_selected = true;
- Repeat_ID = find_unit (Player, Unit);
- Count = 1;
- if (Repeat_ID == -1){
- all_selected = false;
- }
- else{
- while (Repeat_ID != find_unit (Player, Unit)){
- ++ Count;
- }
- if (!object_selected (Player, Repeat_ID)){
- all_selected = false;
- }
- for (UnitCount = 0; UnitCount < Count; ++ UnitCount){
- UnitID = find_unit (Player, Unit);
- if (!object_selected (Player, UnitID)){
- all_selected = false;
- }
- }
- }
- return all_selected;
- */
- }
-
- //============================================================
-
- scenario all_unit_type_near( Player, Type, loc_x, loc_y, distance ) {
- for( object_index = 0; object_index < num_type( Player, Type ); object_index++ ) {
- object_id = find_unit( Player, Type );
- if( !object_near( Player, object_id, loc_x, loc_y, distance ) ) {
- return false;
- }
- }
-
- return true;
- }
-
- //============================================================
-
- scenario all_military_near( Player, loc_x, loc_y, distance ) {
- for( object_index = 0; object_index < num_military_units(Player); object_index++ ) {
- object_id = find_military( Player);
- if( !object_near( Player, object_id, loc_x, loc_y, distance ) ) {
- return false;
- }
- }
-
- return true;
- }
-
- //============================================================
-
- scenario any_unit_type_near( Player, Type, loc_x, loc_y, distance ) {
- for( i = 0; i < num_type( Player, Type ); i++ ) {
- object_id = find_unit( Player, Type );
- if( object_near( Player, object_id, loc_x, loc_y, distance ) ) {
- return true;
- }
- }
-
- return false;
- }
-
-
- //============================================================
- scenario all_military_selected (Player) {
- all_selected = true;
- NumUnits = num_military_units (Player);
- for (Count = 0; Count < NumUnits; Count ++ ){
- UnitID = find_military (Player);
- if (! object_selected (Player,UnitID)){
- all_selected = false;
- }
- }
- return all_selected;
- }
-
- //============================================================
- scenario all_type_active( who, type ) {
- for( i = 0; i < num_type( who, type ); i++ ) {
- unit_id = find_unit( who, type );
- if( is_idle( who, unit_id ) ) {
- return 0;
- }
- }
-
- return 1;
- }
-
- //============================================================
-
- scenario all_type_patrolling( who, type ) {
- for( i = 0; i < num_type( who, type ); i++ ) {
- unit_id = find_all_unit( who, type ) ;
- if( !has_patrol_order( who, unit_id ) ) {
- return 0;
- }
- }
-
- return 1;
- }
-
- //============================================================
-
- scenario all_type_attacking( who, type ) {
- for( i = 0; i < num_type( who, type ); i++ ) {
- unit_id = find_all_unit( who, type ) ;
- if( !has_attack_order( who, unit_id ) ) {
- return 0;
- }
- }
-
- return 1;
- }
-
- //============================================================
- scenario capture_building_type (Captor, Captee, BuildingType, CapturePoint,PostCaptHealth, Message){
- Captured = false;
- FirstID = find_build (Captee, BuildingType);
- LoopID = FirstID;
- NumBuild = num_type (Captee,BuildingType);
- if (LoopID != -1){
- for (Count = 0; Count < NumBuild; ++ Count){
- BuildHealth = object_health (Captee,LoopID);
- if (BuildHealth < CapturePoint){
- NewID = switch_teams (Captor,Captee,LoopID);
- set_object_health (Captor,NewID, PostCaptHealth);
- print_game_msg (Message);
- Captured = true;
- }
- LoopID = find_build (Captee,BuildingType);
- }
- }
- return Captured;
- }
- //============================================================
-
-
- //============================================================
- scenario capture_building (Captor,Captee,BuildingID, CapturePoint,PostCaptHealth, Message,Captured){
- BuildHealth = object_health (Captee,BuildingID);
- if (BuildHealth < CapturePoint && ! Captured){
- NewID = switch_teams (Captor,Captee,BuildingID);
- set_object_health (Captor,NewID,PostCaptHealth);
- print_game_msg (Message);
- Captured = true;
- }
- return Captured;
- }
- //============================================================
-
- //============================================================
- scenario num_object_type_selected (Player, Type) {
- MAX = num_type (Player, Type);
- num = 0;
- for (i = 0; i < MAX; i ++) {
- ID = find_unit (Player, Type);
- if (object_selected (Player, ID)) {
- num ++;
- }
- }
- return num;
- }
- //============================================================
-
- //============================================================
- scenario kill_percent_of_military (Player, percent) {
- total_military = num_military_units (Player);
- count = 0;
- for (i = 0; i < (real)total_military * ((real) percent/100.0); i ++) {
- kill_unit (Player, find_military (Player));
- count ++;
- }
- return count;
- }
- //============================================================
-
-
- //============================================================
- scenario type_has_target_order (Player, type) {
- has_order = false;
- ID = -1;
- for (i = 0; i < num_type (Player, type); i ++) {
- ID = find_unit (Player, type);
- if (has_target_order (Player, ID)) {
- has_order = true;
- }
- }
- return has_order;
- }
- //============================================================
-
-
- //============================================================
- scenario are_any_decoyed (Player) {
- decoyed = false;
- ID = -1;
- for (i = 0; i < num_military_units (Player); i ++) {
- ID = find_military (Player);
- if (is_decoy (Player, ID)){
- decoyed = true;
- }
- }
- return decoyed;
- }
- //============================================================
-
-
- //============================================================
- scenario are_any_entrenched (Player) {
- entrenched = false;
- ID = -1;
- for (i = 0; i < num_military_units (Player); i ++) {
- ID = find_military (Player);
- if (is_entrenched (Player, ID)){
- entrenched = true;
- }
- }
- return entrenched;
- }
- //============================================================
-
- //============================================================
- scenario city_revolt (Player, city_name){
- city_id = find_city_id(city_name);
- city_owner = find_city_owner(city_name);
- new_city_id = switch_teams (Player, city_owner, city_id);
- set_object_health(Player, new_city_id, 75);
- give_good(Player, "Food", 200);
- give_good(Player, "Wealth", 200);
- give_good(Player, "Metal", 100);
- give_good(Player, "Gold", 200);
- x = object_position_x(Player, new_city_id);
- y = object_position_y(Player, new_city_id);
- unit = rand_int(2, 4);
- create_unit(Player, x, y, "Militia", unit);
- chance = rand_int(0, 1);
- if (chance){
- chance = rand_int(0, 1);
- if (chance){
- unit = rand_int(2, 4);
- create_unit(Player, x, y, "Slingers", unit);
- }
- else {
- unit = rand_int(4, 8);
- create_unit(Player, x, y, "Hoplites", unit);
- create_unit(Player, x, y, "Catapult", 1);
- }
- }
- }
-
- //============================================================
-
- scenario cutscene_begin() {
- ui_hide();
- mouse_selection_disable();
- hotkey_selection_disable();
- scrolling_lock();
- zooming_lock();
- }
-
- //============================================================
-
- scenario cutscene_end() {
- ui_show();
- mouse_selection_enable();
- hotkey_selection_enable();
- scrolling_unlock();
- zooming_unlock();
- }
-
- //============================================================
- /*
- SAMPLE CODE:
- if (FRENCH2 == find_city_owner ("Paris")){
- NumUnits = num_civilian_units (FRENCH1) + num_military_units (FRENCH1);
- for (Count = 0; Count < NumUnits; ++ Count){
- NapX = object_position_x (FRENCH1,NapoleanID);
- NapY = object_position_y (FRENCH1,NapoleanID);
- UnitID = find_unit (FRENCH2,"");
- if (object_near (FRENCH2,UnitID,NapX,NapY,NapRadius)){
- switch_teams (FRENCH1,FRENCH2,UnitID);
- }
- }
- }
- */
- //============================================================
- /*****************************************************************/